package com.xbongbong.pro.statistic.enums;

import com.xbongbong.i18n.util.I18nMessageUtil;
import lombok.Getter;

import java.util.Objects;

/**
 * @ClassName TimeDimensionEnum
 * @Description 时间维度枚举
 * @Author mengna.Deng
 * @Date 2021/10/9 14:33
 * @Version 1.0
 */
@Getter
public enum TimeDimensionEnum {
    /**
     * 日
     */
    DAY(0, "enum.timeDimensionEnum.name.day", "day","y-M-d"),
    /**
     * 周
     */
    WEEK(1, "enum.timeDimensionEnum.name.week", "week","y-W"),
    /**
     * 月
     */
    MONTH(1, "enum.timeDimensionEnum.name.month", "month","y-M"),
    /**
     * 季度
     */
    QUARTER(1, "enum.timeDimensionEnum.name.quarter", "quarter","y-q"),
    /**
     * 年
     */
    YEAR(1, "enum.timeDimensionEnum.name.year", "year","y"),
    ;

    private final Integer code;

    private final String name;

    private final String alias;

    private String format;

    TimeDimensionEnum(Integer code, String name, String alias,String format) {
        this.code = code;
        this.name = name;
        this.alias = alias;
        this.format = format;
    }
    /**
     * 根据格式化信息返回枚举
     * @param format 格式化信息
     * @return 枚举类型
     */
    public static TimeDimensionEnum getByFormatStr(String format) {
        for (TimeDimensionEnum timeDimensionEnum : values()) {
            if (Objects.equals(format, timeDimensionEnum.getFormat())) {
                return timeDimensionEnum;
            }
        }
        return DAY;
    }
    public String getName() {
        return I18nMessageUtil.getMessage(name);
    }
}
